package com.example.star.retrofit;

import com.example.star.api_service.ApiAddress;
import com.example.star.api_service.ApiBuyNow;
import com.example.star.api_service.ApiFavorite;
import com.example.star.api_service.ApiFollow;
import com.example.star.api_service.ApiPerimeter;
import com.example.star.api_service.ApiShoppingCart;
import com.example.star.api_service.ApiStar;
import com.example.star.api_service.ApiUser;
import com.example.star.api_service.ApiFeedback;
import com.example.star.api_service.MessageApi;
import com.example.star.api_service.PostApi;
import com.example.star.api_service.SongApi;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class ApiClient {
//    private static final String BASE_URL = "http://192.168.2.14:8080/"; //主机ip地址
    private static final String BASE_URL = "http://192.168.43.38:8080/"; //主机ip地址
//    private static final String BASE_URL = "http://10.0.2.2:8080/";//虚拟机ip地址
    private static Retrofit retrofit;

    public static Retrofit getClient() {
        if (retrofit == null) {
            Gson gson = new GsonBuilder()
                    .setLenient()
                    .create();

            retrofit = new Retrofit.Builder()
                    .baseUrl(BASE_URL)
                    .addConverterFactory(GsonConverterFactory.create(gson))
                    .build();
        }
        return retrofit;
    }

    public static ApiUser getApiUser() {
        return getClient().create(ApiUser.class);
    }

    public static ApiStar getApiStar() {
        return getClient().create(ApiStar.class);
    }
    public static ApiFollow getApiFollow() {
        return getClient().create(ApiFollow.class);
    }

    public static ApiPerimeter getApiPerimeter() {
        return getClient().create(ApiPerimeter.class);
    }
    public static ApiFavorite getApiFavorite() {
        return getClient().create(ApiFavorite.class);
    }
    public static ApiShoppingCart getApiShoppingCart() {
        return getClient().create(ApiShoppingCart.class);
    }
    public static ApiBuyNow getApiBuyNow() {
        return getClient().create(ApiBuyNow.class);
    }
    public static MessageApi getMessageApi() {
          return getClient().create(MessageApi.class);
    }
    public static PostApi getPostApi() {
        return getClient().create(PostApi.class);
    }
    public static ApiAddress getApiAddress() {
        return getClient().create(ApiAddress.class);
    }
    public static ApiFeedback getApiFeedback() {
        return getClient().create(ApiFeedback.class);
    }
    public static SongApi getSongApi() {
        return getClient().create(SongApi.class);
    }

}
